package com.runfast.waimai.web.controller;

import com.runfast.common.utils.TokenUtil;
import com.runfast.common.web.controller.BaseController;
import com.runfast.common.web.entity.Result;
import com.runfast.paotui.dao.model.Order;
import com.runfast.paotui.dao.model.OrderExample;
import com.runfast.paotui.dao.model.RunfastAgentbusiness;
import com.runfast.paotui.service.OrderService;
import com.runfast.paotui.service.RunfastAgentbusinessService;
import com.runfast.waimai.dao.model.BsTravelAdvert;
import com.runfast.waimai.dao.model.RunfastBusiness;
import com.runfast.waimai.dao.model.RunfastHomepage;
import com.runfast.waimai.service.BsTravelAdvertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 跑腿订单接口
 */
@RestController("userWmHomeController")
@RequestMapping(value= "/api/user/wm/home", headers = "token")
public class HomeController{


    @Autowired
    private BsTravelAdvertService advertService;


    @Autowired
    private RunfastAgentbusinessService agentbusinessService;
    /**
     *
     * 根据用户当前的位置获取默认的代理商id
     * @param longitude 用户当前的经度
     * @param latitude 用户当前的纬度
     * @param token
     * @return
     */
    @PostMapping("/agent")
    public Result agent(@RequestParam double longitude, @RequestParam double latitude, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);

        Integer agentId = agentbusinessService.getDefaultAgentId(longitude, latitude);

        return Result.ok("", agentId);
    }

    /**
     * 根据代理商id获取首页轮播广告列表
     * @param agentId 代理商id
     * @param pageable
     * @param token
     * @return
     */
    @PostMapping("/adverts")
    public Result<List<BsTravelAdvert>> adverts(@RequestParam int agentId, @PageableDefault Pageable pageable, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);



        return Result.ok("");
    }


    /**
     * 根据代理商id获取首页商户分类
     * @param agentId 代理商id
     * @param pageable
     * @param token
     * @return
     */
    @PostMapping("/catalogs")
    public Result<List<RunfastHomepage>> catalogs(@RequestParam int agentId, @PageableDefault Pageable pageable, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);


        return Result.ok("");
    }


    /**
     *
     * 根据名称搜索商家或者商品
     * @param longitude 用户当前经度
     * @param latitude 用户当前纬度
     * @param name 商家名或者商品名
     * @param agentId 代理商id
     * @param pageable
     * @param token
     * @return
     */
    @PostMapping("/search")
    public Result<List<Map>> search(@RequestParam double longitude, @RequestParam double latitude, @RequestParam String name, @RequestParam int agentId, @PageableDefault Pageable pageable, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);


        return Result.ok("");
    }

    /**
     *
     * 获取优惠专区大额满减活动商家列表
     * @param agentId 代理商id
     * @param pageable
     * @param token
     * @return
     */
    @PostMapping("/fullLessZone")
    public Result<List<RunfastBusiness>> fullLessZone(@RequestParam int agentId, @PageableDefault Pageable pageable, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);


        return Result.ok("");
    }

    /**
     *
     * 获取优惠专区免配送费活动商家列表
     * @param agentId 代理商id
     * @param pageable
     * @param token
     * @return
     */
    @PostMapping("/freeDeliveryZone")
    public Result<List<RunfastBusiness>> freeDeliveryZone(@RequestParam int agentId, @PageableDefault Pageable pageable, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);


        return Result.ok("");
    }

    /**
     * 获取特惠优选商品列表
     * @param agentId
     * @param pageable
     * @param token
     * @return
     */
    @PostMapping("/offZone")
    public Result<List<RunfastBusiness>> offZone(@RequestParam int agentId, @PageableDefault Pageable pageable, @RequestHeader String token) {
        Integer userId = TokenUtil.getUserId(token);


        return Result.ok("");
    }





}
